package ldkxingzhe.ldkxingzhedemo.alarm;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;

import ldkxingzhe.ldkxingzhedemo.utils.LogDemo;

/**
 * Created by ke on 15-9-20.
 */
public class BootReceiver extends BroadcastReceiver{

    private final String TAG = BootReceiver.class.getSimpleName();
    private final long PERIOD = 3000;
    @Override
    public void onReceive(Context context, Intent intent) {
        LogDemo.v(TAG,"onReceive");
        dealWithSchedule(context);
    }

    private void dealWithSchedule(Context context){
        AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(context,LogService.class);
        PendingIntent pendingIntent = PendingIntent.getService(context,0,intent,0);
        mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime() +  PERIOD,
                PERIOD,
                pendingIntent);
    }
}
